package com.example.demo_one.kotlin

fun main() {
    val car = Car("自行车")
    car.show()
    val car2 = Car("小轿车")
    car2.show()
    val car3 = Car("自定义车", 50)
    car3.show()
}

class Car(var name: String) {
    var wheels = 0

    // 初始代码块
    init {
        wheels = when (name) {
            "自行车" -> 2
            "小轿车" -> 4
            "大货车" -> 12
            else -> 4
        }
    }

    //    次构造函数
    constructor(name: String, wheels: Int) : this(name) {
        this.wheels = wheels
    }

    fun show() {
        println("车龄名称:$name , 车轮数量:$wheels")
    }
}